-- @owner: ningyali
-- @date: 2024-12-19
-- @testpoint: HTAP行列融合特性--不支持事务中操作(分区表)，合理报错

--step1:建表插入数据; expect:执行成功
@conn SingleDbUser;
drop table if exists t_htap_single_0109_1;
create table t_htap_single_0109_1(
    c1 integer(20),
    c2 varchar(20) not null default '',
    c3 char(30)
)
partition by range (c1)
(
    partition t_htap_single_0109_1_p1 values less than (100),
    partition t_htap_single_0109_1_p2 values less than (200),
    partition t_htap_single_0109_1_p3 values less than (300),
    partition t_htap_single_0109_1_p4 values less than (400),
    partition t_htap_single_0109_1_p5 values less than (MAXVALUE)
);

drop table if exists t_htap_single_0109_2;
create table t_htap_single_0109_2(
    c1 date,
    c2 int,
    c3 char(30)
)
partition by range (c1) subpartition by range(c2)
(
    partition t_htap_single_0109_2_p1 values less than ('2024-03-01')
    (
        subpartition t_htap_single_0109_2_p1_1 values less than(50),
        subpartition t_htap_single_0109_2_p1_2 values less than(100)
    ),
    partition t_htap_single_0109_2_p2 values less than ('2024-08-01')
    (
        subpartition t_htap_single_0109_2_p2_1 values less than(50),
        subpartition t_htap_single_0109_2_p2_2 values less than(100)
    ),
    partition t_htap_single_0109_2_p3 values less than ('2024-12-30')
    (
        subpartition t_htap_single_0109_2_p3_1 values less than(50),
        subpartition t_htap_single_0109_2_p3_2 values less than(100)
    ),
    partition t_htap_single_0109_2_p4 values less than ('2025-6-30')
    (
        subpartition t_htap_single_0109_2_p4_1 values less than(50),
        subpartition t_htap_single_0109_2_p4_2 values less than(100)
    ),
    partition t_htap_single_0109_2_p5 values less than ('2025-12-30')
    (
        subpartition t_htap_single_0109_2_p5_1 values less than(50),
        subpartition t_htap_single_0109_2_p5_2 values less than(100)
    )
);

insert into t_htap_single_0109_1 values (
generate_series(1, 1000),
generate_series(1, 1000)||'aaa',
generate_series(1, 1000)||'bbb');

insert into t_htap_single_0109_2 select generate_series(
'2024-01-01'::timestamp, '2024-01-01'::timestamp + interval '720 days', '20 day'::interval),
generate_series(1, 99),
generate_series(1, 99)||'abc';

--step2:事务中全表转换; expect:合理报错
start transaction;
    alter table t_htap_single_0109_1 imcstored;
commit;

start transaction;
    alter table t_htap_single_0109_2 imcstored;
rollback;

begin;/
    alter table t_htap_single_0109_1 imcstored;
commit;

--step3:事务中部分列转换; expect:合理报错
start transaction;
    alter table t_htap_single_0109_1 imcstored(c1, c2);
commit;

start transaction;
    alter table t_htap_single_0109_2 imcstored(c1, c2);
rollback;

begin;/
    alter table t_htap_single_0109_1 imcstored(c1, c2);
commit;

--step4:事务中指定分区转换; expect:合理报错
start transaction;
    alter table t_htap_single_0109_1 modify partition t_htap_single_0109_1_p1 imcstored;
commit;

start transaction;
    alter table t_htap_single_0109_2 modify partition t_htap_single_0109_2_p1 imcstored;
rollback;

begin;/
    alter table t_htap_single_0109_1 modify partition t_htap_single_0109_1_p1 imcstored;
commit;

--step5:事务中指定分区部分列转换; expect:合理报错
start transaction;
    alter table t_htap_single_0109_2 modify partition t_htap_single_0109_2_p1 imcstored(c2, c3);
commit;

start transaction;
    alter table t_htap_single_0109_1 modify partition t_htap_single_0109_1_p1 imcstored(c2, c3);
rollback;

begin;/
    alter table t_htap_single_0109_2 modify partition t_htap_single_0109_2_p1 imcstored(c2, c3);
commit;

--step6:清理环境; expect:执行成功
@conn SingleDbUser;
drop table if exists t_htap_single_0109_1 cascade;
drop table if exists t_htap_single_0109_2 cascade;
